<?php
class Backend_Designer_Sub{
	/**
	 * @var Lang
	 */
	protected $_lang;
	/**
	 * @var Zend_Db_Adapter_Abstract
	 */
	protected $_db;
	/**
	 * Designer config
	 * @var Config_File_Array
	 */
	protected $_config;
	/**
	 * @var Store_Session
	 */
	protected $_session;
	/**
	 * @var Designer_Storage_Adapter_Abstract
	 */
	protected $_storage;
	
	
	public function __construct()
	{
		$this->_lang = Lang::getInstance();
		$this->_db = Application::getDbConnection();
		$this->_config = Config::factory(Config::File_Array, Application::getConfig()->get('configs').'designer.php');
		$this->_session = Store_Session::getInstance('Designer');
		$this->_storage = Designer_Storage::getInstance($this->_config->get('storage'));
		if($this->_config->get('storage') === 'file')
			Designer_Storage_Adapter_File::setConfigsPath($this->_config->get('configs'));
	}
	/**
	 * Check if project is loaded
	 */	
	protected function _checkLoaded()
	{
		if(!$this->_session->keyExists('loaded') || !$this->_session->get('loaded'))
			Response::jsonError($this->_lang->MSG_PROJECT_NOT_LOADED);	
	}
	/**
	 * Get project object from
	 * session storage
	 * @return Designer_Project
	 */
	protected function _getProject(){
		return $this->_session->get('project');
	}
	/**
	 * Store project data
	 */
	protected function _storeProject(){
		$this->_session->set('project', $this->_getProject());
	}
}